package zheezes.protocol.impl.gbw.bean;

import java.util.ArrayList;
import java.util.List;

import zheezes.protocol.impl.gbw.format.DataForm24;
import zheezes.util.ByteUtil;


public class VipFrozenData {
	private short seq;
	private byte days;
	private List<DataForm24[]> list = new ArrayList<DataForm24[]>();

	public void addData(DataForm24[] data) {
		list.add(data);
	}

	public DataForm24[][] getDatas() {
		return list.toArray(new DataForm24[0][]);
	}

	public int sizeof() {
		return 2 + 1 + days * 168;
	}

	public int getBytes(byte[] buf, int offset) {
		assert list.size() == days;
		int idx = offset;
		ByteUtil.stoc(buf, idx, seq);
		idx += 2;
		buf[idx++] = days;
		for (DataForm24[] dfs : list) {
			assert dfs.length == 24;
			for (DataForm24 df : dfs) {
				idx += df.getBytes(buf, idx);
			}
		}

		return idx - offset;
	}

	public int setBytes(byte[] buf, int offset) {
		int idx = offset;
		seq = ByteUtil.ctos(buf, idx);
		idx += 2;
		days = buf[idx++];
		for (int i = 0; i < days; i++) {
			DataForm24[] dfs = new DataForm24[24];
			for (int j = 0; j < dfs.length; j++) {
				DataForm24 df = new DataForm24();
				idx += df.setBytes(buf, idx);
				dfs[j] = df;
			}
			list.add(dfs);
		}

		return idx - offset;
	}

	public short getSeq() {
		return seq;
	}

	public void setSeq(short seq) {
		this.seq = seq;
	}

	public byte getDays() {
		return days;
	}

	public void setDays(byte days) {
		this.days = days;
	}
}
